package cool.tsy.emos.wx.service.impl;

import cool.tsy.emos.wx.db.dao.MessageDao;
import cool.tsy.emos.wx.db.dao.MessageRefDao;
import cool.tsy.emos.wx.db.pojo.Message;
import cool.tsy.emos.wx.db.pojo.MessageRef;
import cool.tsy.emos.wx.service.MessageService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author: hongxuan.wang
 * @date: Created in 2021/11/30 23:26
 * @description:
 * @mail: 1443424326@qq.com
 */
@Service
public class MessageServiceImpl implements MessageService {

    private final MessageDao messageDao;

    private final MessageRefDao messageRefDao;

    public MessageServiceImpl(MessageDao messageDao, MessageRefDao messageRefDao) {
        this.messageDao = messageDao;
        this.messageRefDao = messageRefDao;
    }

    @Override
    public String insertMessage(Message message) {
        String id = messageDao.insert(message);
        return id;
    }

    @Override
    public String insertRef(MessageRef messageRef) {
        String id = messageRefDao.insert(messageRef);
        return id;
    }

    @Override
    public long searchUnreadCount(int userId) {
        long count = messageRefDao.searchUnreadCount(userId);
        return count;
    }

    @Override
    public long searchLastCount(int userId) {
        long count = messageRefDao.searchLastCount(userId);
        return count;
    }

    @Override
    public List<HashMap> searchMessageByPage(int userId, long start, int length) {
        List<HashMap> list = messageDao.searchMessageByPage(userId, start, length);
        return list;
    }

    @Override
    public HashMap searchMessageById(String id) {
        HashMap map = messageDao.searchMessageById(id);
        return map;
    }

    @Override
    public long updateUnreadMessage(String id) {
        long rows = messageRefDao.updateUnreadMessage(id);
        return rows;
    }

    @Override
    public long deleteMessageRefById(String id) {
        long rows = messageRefDao.deleteMessageRefById(id);
        return rows;
    }

    @Override
    public long deleteUserMessageRef(int userId) {
        long rows = messageRefDao.deleteUserMessageRef(userId);
        return rows;
    }
}
